import java.util.concurrent.locks.ReentrantLock;

/**
 * @version 1.8
 * @Author Djx_hmbb
 * @Date 2023/8/24 9:12
 * @注释:ReentrantLock->可重入的,新的加锁方式
 */
public class ThreadDemo27 {
    public static void main(String[] args) {
        ReentrantLock reentrantLock = new ReentrantLock(true);
//        reentrantLock.lock();
        boolean result = reentrantLock.tryLock();
        try {
            if (result) {
                //加上锁
            } else {
                //未加上锁
            }
        } finally {
            if (result) {
                //加上锁
                reentrantLock.unlock();
            }
        }
    }
}
